function deleteFromList() {
	var inputs = document.getElementsByTagName('input');
	var checkboxes = [];
	for (var i = 0; i < inputs.length; i++) {  
		if(inputs[i].className == 'checkBox'){
			checkboxes.push(inputs[i]);
		}
	}
	var result = false;
	for ( var i = 0; i < checkboxes.length; i++) {
		if (checkboxes[i].checked) {
			result = true;
			break;
		}
	}
	if (!result) {
		alert(noSelectedNews);
		return false;
	}
	var agree = confirm(confirmDeleteList);
	if (agree) {
		return true;
	} else {
		return false;
	}
}

function deleteFromView(clicked) {
	if(clicked == 'delete'){
		var agree = confirm(confirmdDeleteNews);
		return agree;
	}
	return true;
}
function validateNewsForm(clicked) {
	if(clicked == 'cancel'){
		return true;
	}
	var messages = new Array();
	var isValid = true;
	var element = document.getElementById('add-news-form:add-news-title');
	if((element.value == '') || (element.value.length > 100)) {
		isValid =  false;
		messages.push(invalidTitle);
	}
	element = document.getElementById('add-news-form:add-news-date');
	if((element.value == '') || (element.value.length > 10)){
		isValid = false;
		messages.push(invalidDate+datePattern);
	}else {
		var MONTH = "MM";
		var DAY = "dd";
		var YEAR = "yyyy";
		var dateRegexp;
		var orderMonth = datePattern.indexOf(MONTH);
		var orderDay = datePattern.indexOf(DAY);
		var orderYear = datePattern.indexOf(YEAR);
		if ((orderDay < orderYear && orderDay > orderMonth)) {
			var iDelim1 = orderMonth + MONTH.length;
			var iDelim2 = orderDay + DAY.length;
			var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
			var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
			if (iDelim1 == orderDay && iDelim2 == orderYear) {
				dateRegexp = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$");
			} else if (iDelim1 == orderDay) {
				dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$");
			} else if (iDelim2 == orderYear) {
				dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$");
			} else {
				dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{4})$");
			}
			var matched = dateRegexp.exec(element.value);
			if(matched != null) {
				if (!jcv_isValidDate(matched[2], matched[1], matched[3])) {
					isValid = false;
					messages.push(invalidDate+datePattern);
				}
			} else {
				isValid = false;
				messages.push(invalidDate+datePattern);
			}
		} else if ((orderMonth < orderYear && orderMonth > orderDay)) {
			var iDelim1 = orderDay + DAY.length;
			var iDelim2 = orderMonth + MONTH.length;
			var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
			var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
			if (iDelim1 == orderMonth && iDelim2 == orderYear) {
				dateRegexp = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$");
			} else if (iDelim1 == orderMonth) {
				dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$");
			} else if (iDelim2 == orderYear) {
				dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$");
			} else {
				dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{4})$");
			}
			var matched = dateRegexp.exec(element.value);
			if(matched != null) {
				if (!jcv_isValidDate(matched[1], matched[2], matched[3])) {
					isValid = false;
					messages.push(invalidDate+datePattern);
				}
			} else {
				isValid = false;
				messages.push(invalidDate+datePattern);
			}
		} else if ((orderMonth > orderYear && orderMonth < orderDay)) {
			var iDelim1 = orderYear + YEAR.length;
			var iDelim2 = orderMonth + MONTH.length;
			var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
			var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
			if (iDelim1 == orderMonth && iDelim2 == orderDay) {
				dateRegexp = new RegExp("^(\\d{4})(\\d{2})(\\d{2})$");
			} else if (iDelim1 == orderMonth) {
				dateRegexp = new RegExp("^(\\d{4})(\\d{2})[" + delim2 + "](\\d{2})$");
			} else if (iDelim2 == orderDay) {
				dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})(\\d{2})$");
			} else {
				dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{2})$");
			}
			var matched = dateRegexp.exec(element.value);
			if(matched != null) {
				if (!jcv_isValidDate(matched[3], matched[2], matched[1])) {
					isValid = false;
					messages.push(invalidDate + datePattern);
				}
			} else {
				isValid = false;
				messages.push(invalidDate+datePattern);
			}
		} else {
			isValid = false;
			messages.push(invalidDate+datePattern);
		} 
	}
	element = document.getElementById('add-news-form:news-brief');
	if((element.value == '') || (element.value.length > 500)) {
		isValid = false;
		messages.push(invalidBrief);
	}
	element = document.getElementById('add-news-form:news-content');
	if((element.value == '') || (element.value.length > 2048)){
		isValid = false;
		messages.push(invalidContent);
	}
	if(!isValid){
		var message = '';
		for(var i = 0; i < messages.length; i++){
			message += messages[i];
			message += '\n';
		}
		alert(message);
		return false;
	}
	return true;	
}

function jcv_isValidDate(day, month, year) {
	if (month < 1 || month > 12) {
		return false;
	}
	if (day < 1 || day > 31) {
		return false;
	}
	if ((month == 4 || month == 6 || month == 9 || month == 11) &&
			(day == 31)) {
		return false;
	}
	if (month == 2) {
		var leap = (year % 4 == 0 &&
				(year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day == 29 && !leap)) {
			return false;
		}
	}
	return true;
}